//
//  LXDanMu.m
//  cat
//
//  Created by imera on 16/3/9.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "LXDanMu.h"

@implementation LXDanMu

+ (instancetype)initWithDict:(NSDictionary *)dict
{
    return [[self alloc]initWithDict:dict];
}

- (instancetype)initWithDict:(NSDictionary *)dict
{
    if (dict != nil) {
        if (![dict[@"danmu"] isEqualToString:@""]) {
            //字符串处理
            NSString *text = dict[@"danmu"];
            NSString *text1 = [[text stringByReplacingOccurrencesOfString:@":" withString:@""] stringByReplacingOccurrencesOfString:@"," withString:@""];
            NSMutableArray *textArr = [NSMutableArray arrayWithArray:[text1 componentsSeparatedByString:@"\""]];
            //去除无用字符串
            for (int i=0;i<textArr.count;i++) {
                if ([textArr[i] isEqualToString:@""]) {
                    [textArr removeObjectAtIndex:i];
                }
            }
            [textArr removeObjectAtIndex:0];
            self.text = textArr[1];
            self.color = textArr[3];
            self.font = [textArr[5] integerValue] + 17;
            self.position = [textArr[7] integerValue];
            self.time = [[textArr[9] stringByReplacingOccurrencesOfString:@"}" withString:@""] integerValue];
        }
        
        self.ID = dict[@"id"];
        self.parentid = dict[@"parentid"];
        self.posttime = 0;
        
    }
    
    return [self init];
}

@end
